﻿@using Telerik.Web.Mvc.UI;
@using Helena.Areas.Configuraciones.Models;
@using Helena.Areas.Ventas.Models;
@model VentaView


@{
    ViewBag.Title = "Venta Ticket";
    Layout = "~/Views/Shared/_Layout.cshtml";
    ConfiguracionView conf = (ConfiguracionView)Session["Configuracion"];
    VentaView ven = (VentaView)Session["NuevaVenta"];
}

@Html.Telerik().ScriptRegistrar().Globalization(true)
<script type="text/javascript">

    function onChange(e) {

    var PSE= parseFloat($("#Pago_en_Efectivo_en_Soles").val())
    var PST= parseFloat($("#Pago_con_Tarjeta_en_Soles").val())
    var PDE= parseFloat($("#Pago_en_Efectivo_en_Dolares").val()*@(conf.TipoCambio))
    
    var porcentaje = parseFloat($("#Descuento").val())
    var total = parseFloat($("#Sub_Total").val())
    
    $("#Total_En_Soles").val(Math.round((total*(100-porcentaje)/100)*100)/100)
    $("#vuelto").val(Math.round(-(total*(100-porcentaje)/100-(PSE+PST+PDE))*100)/100)
    }

    function cambio() {

    var PSE= parseFloat($("#Pago_en_Efectivo_en_Soles").val())
    var PST= parseFloat($("#Pago_con_Tarjeta_en_Soles").val())
    var PDE= parseFloat($("#Pago_en_Efectivo_en_Dolares").val()*@(conf.TipoCambio))
    
    var porcentaje = parseFloat($("#Descuento").val())
    var total = parseFloat($("#Sub_Total").val())

    $("#Total_En_Soles").val(Math.round((total*(100-porcentaje)/100)*100)/100)
    $("#vuelto").val(Math.round(-(total*(100-porcentaje)/100-(PSE+PST+PDE))*100)/100)
    }

    function onLoad(e) {
        setInterval( "cambio()", 5000 );
    }
</script>

<h2>Venta Ticket</h2>
@using (Html.BeginForm())
{
    <fieldset>
        <legend>Datos del sistema</legend>
            <table style="width:100%">
                <tr>
                    <td>
                        <div class="editor-label">@Html.LabelFor(m => m.Fecha)</div>
                        <div class="editor-field">@Html.Telerik().AutoCompleteFor(m => m.Fecha)@Html.ValidationMessageFor(m => m.Fecha)</div>
                    </td>
                    <td>
                        <div class="editor-label">@Html.LabelFor(m => m.Ticket)</div>
                        <div class="editor-field">@Html.Telerik().AutoCompleteFor(m => m.Ticket)@Html.ValidationMessageFor(m => m.Ticket)</div>
                    </td>
                    <td>
                        <div class="editor-label">Tipo de Cambio</div>
                        <div class="editor-field">S/. @conf.TipoCambio</div>
                    </td>
                    <td>
                        <div class="editor-label">Valor del IGV</div>
                        <div class="editor-field">@conf.ValorIGV %</div>
                    </td>
                    <td>
                        <div class="editor-label">@Html.LabelFor(m => m.VendedorID)</div>
                        <div class="editor-field">@(Html.Telerik().DropDownList().Name("VendedorID")
                                                    .SelectedIndex(1)
                                                    .BindTo(new SelectList((ICollection<Helena.Areas.Vendedores.Models.VendedorView>)Session["vendedores"], "ID", "NombreLargo"))
                                                    .HtmlAttributes(new { style = string.Format("width:{0}px", 200) })
                                                    )@Html.ValidationMessageFor(m => m.VendedorID)</div>
                    </td>
                    <td>
                        <div class="editor-label">@Html.LabelFor(m => m.ClienteID)</div>
                        <div class="editor-field">@(Html.Telerik().ComboBox().Name("ClienteID")
                                                    .SelectedIndex(1)
                                                    .BindTo(new SelectList((ICollection<Helena.Areas.Clientes.Models.ClienteView>)Session["clientes"], "ID", "RazonSocial"))
                                                    .HtmlAttributes(new { style = string.Format("width:{0}px", 150) })
                                                    )@Html.ValidationMessageFor(m => m.ClienteID)</div>                                                    
                    </td>
                </tr>
            </table>
    </fieldset>

    <fieldset>
        <legend>Resumen de la Venta</legend>
            <table style="width:100%">
                <tr>
                    <td>
                        <table>
                            <tr>
                                <th>@Html.LabelFor(model => model.Descuento)</th>
                                <td>@Html.Telerik().PercentTextBoxFor(model => model.Descuento).Value(0.00).InputHtmlAttributes(new { style = "font-size:30px" }).ClientEvents(events => events.OnChange("onChange"))
                                    @Html.ValidationMessageFor(model => model.Descuento)</td>
                            </tr>
                            <tr>
                                <th>@Html.LabelFor(model => model.Valor_Del_Igv_En_Soles)</th>
                                <td>@Html.Telerik().CurrencyTextBoxFor(model => model.Valor_Del_Igv_En_Soles).DecimalDigits(2).CurrencySymbol("S/").InputHtmlAttributes(new { style = "font-size:30px" })
                                    @Html.ValidationMessageFor(model => model.Valor_Del_Igv_En_Soles)</td>
                            </tr>
                            <tr>
                                <th>@Html.LabelFor(model => model.Sub_Total)</th>
                                <td>@Html.Telerik().CurrencyTextBoxFor(model => model.Sub_Total).InputHtmlAttributes(new { style = "font-size:30px" }).DecimalDigits(2).CurrencySymbol("S/").ClientEvents(events => events.OnLoad("onLoad"))
                                    @Html.ValidationMessageFor(model => model.Sub_Total)</td>
                            </tr>
                            <tr>
                                <th>Total :</th>
                                <td style="font-size:medium">@Html.TextBox("Total_En_Soles", @Model.Total_En_Soles, new { style = "font-size:30px" })</td>
                            </tr>
                            <tr>
                                <th>Vuelto :</th>
                                <td style="font-size:medium">@Html.TextBox("vuelto",0,new { style = "font-size:30px" })</td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <table>
                <tr>
                    <th>@Html.LabelFor(model => model.Pago_en_Efectivo_en_Soles)</th>
                    <td>@Html.Telerik().CurrencyTextBoxFor(model => model.Pago_en_Efectivo_en_Soles).CurrencySymbol("S/").ClientEvents(events => events.OnChange("onChange")).InputHtmlAttributes(new { style = "font-size:30px" })
                        @Html.ValidationMessageFor(model => model.Pago_en_Efectivo_en_Soles)</td>
                </tr> 
                <tr>
                    <th>@Html.LabelFor(model => model.Pago_en_Efectivo_en_Dolares)</th>
                    <td>@Html.Telerik().CurrencyTextBoxFor(model => model.Pago_en_Efectivo_en_Dolares).CurrencySymbol("US$").ClientEvents(events => events.OnChange("onChange")).InputHtmlAttributes(new { style = "font-size:30px" })
                        @Html.ValidationMessageFor(model => model.Pago_en_Efectivo_en_Dolares)</td>
                </tr>
                <tr>
                    <th>@Html.LabelFor(model => model.Pago_con_Tarjeta_en_Soles)</th>
                    <td>@Html.Telerik().CurrencyTextBoxFor(model => model.Pago_con_Tarjeta_en_Soles).CurrencySymbol("S/").ClientEvents(events => events.OnChange("onChange")).InputHtmlAttributes(new { style = "font-size:30px" })
                        @Html.ValidationMessageFor(model => model.Pago_con_Tarjeta_en_Soles)</td>
                </tr>
                <tr>
                    <th>@Html.LabelFor(model => model.tarjetaID)</th>
                    <td>
                    @( Html.Telerik().ComboBox()
                        .Name("TarjetaID").AutoFill(true).SelectedIndex(Model.tarjetaID)
                        .BindTo(new SelectList((IEnumerable<TarjetaView>)Session["Tarjetas"], "ID", "Descripcion"))
                        .HtmlAttributes(new { style = string.Format("width:{0}px", 200) })
                        .HighlightFirstMatch(true)
                        .OpenOnFocus(true)
                        )
                    </td>
                </tr>
            </table>
                    </td>
                </tr>
            </table>

    </fieldset>

    <p><input type="submit" value="Guardar Ticket" /></p>
}
